﻿$(document).ready(function() {
    BindQX();
});
function BindQX() {
    //全选绑定
    $("input[type='checkbox'][id^='DWID']").each(function() {
        $(this).bind("click", function(event) {
            event.stopPropagation();
            var bindxq = $("#AllHiddenField");
            var Number = $(this).attr("id").toString().search("DWID") + 4;
            var dwid = $(this).attr("id").toString().substr(Number, 8);
            if ($(this).attr("checked") != "") {
                $("input[type='checkbox'][id*='DWID_" + dwid + "']").each(function() {
                    if ($(this).attr("checked") == "") {
                        $(this).attr("checked", "checked");
                        $(this).next().css("font-weight", "bold");
                        GetAddDel($(this));
                    }
                })
                bindxq.val(bindxq.val() + "DWID" + dwid + ",");
                //alert(bindxq.val());
            }
            else {
                $("input[type='checkbox'][id*='DWID_" + dwid + "']").each(function() {
                    if ($(this).attr("checked") != "") {
                        $(this).removeAttr("checked");
                        $(this).next().css("font-weight", "");
                        GetAddDel($(this));
                    }
                })
                bindxq.val(bindxq.val().toString().replace("DWID" + dwid + ",", ""));
                //alert(bindxq.val());
            }
        });
    })
    
    //点击绑定
    $("input[type='checkbox'][id*='content_DWID']").each(function() {
        $(this).bind("click", function() {
            GetAddDel($(this));
        })
    })

    $("tr[id^='DWID']").each(function() {
        var id = $(this).attr("id").toString();
        if (id.length == 12) {
            $(this).bind("click", function() {
                $("tr[id*='" + id + "']").each(function() {
                    if ($(this).attr("id") != id) {
                        $(this).slideToggle();
                    }
                })
            })
        }
    })
}

function GetAddDel(check) {
    var cyry = check.attr("value");
    //alert(cyry);
    var bindcyry = $("#BindHiddenField");
    var addcyry = $("#AddHiddenField");
    var delcyry = $("#DelHiddenField");
    if (check.attr("checked") != "") {
        if (bindcyry.val().toString().indexOf(cyry) != -1)//如果与原先集合比较，存在去掉删除集合中的编号
        {
            delcyry.val(delcyry.val().toString().replace("'" + cyry + "',", ""));
        }
        else {
            addcyry.val(addcyry.val() + "'" + cyry + "',");
        }
        check.next().css("font-weight", "bold");
    }
    else {
        if (addcyry.val().toString().indexOf(cyry) != -1)//如果与添加集合比较，存在删掉
        {
            addcyry.val(addcyry.val().toString().replace("'" + cyry + "',", ""));
        }
        else {
            delcyry.val(delcyry.val() + "'" + cyry + "',");
        }
        check.next().css("font-weight", "");
    }
    //$("#ctl00_MainContent_Label2").text(bindcyry.val());
    //$("#ctl00_MainContent_Label3").text(addcyry.val());
    //$("#ctl00_MainContent_Label4").text(delcyry.val());
}